#!/usr/bin/python
"""
*******************************************************************
NAME
	stockm.py

SYNOPSIS
	stockm.py [OPTION] 

DESCRIPTION
	Monitor your stocks and calculate particular profit simply.
	
	--cname, -c
	  display the result with chinese name 

	--self, -s
	  display the result without sorting for your securities

	--nosort, -n
	  display the result without sorting

	--help,	-h
	  display this help and exit

	--version
	  output version information and exit
EXAMPLES
	\>stockm.py

AUTHOR
	Written by Ryan Chang

REPORTING BUGS
	Report bugs to <ryan.cx@gmail.com>

REFERENCE 
	http://finance.yahoo.com/
	http://mis.tse.com.tw/Best5_new.html?StkNo=2382
	http://mis.tse.com.tw/data/2382.csv
	http://mis.tse.com.tw/indextseX.html
	http://mis.tse.com.tw/data/TSEIndex.csv
*******************************************************************
"""
import os,sys
import getopt
from stock.StockInfo import stockinfo


def main():
	"""REVISION: 1.0"""
	nosort=0
	cname=0
	self_profile=".quote.TW"
	ref_profile=".mquote.TW",
	# parse command line options
	try:
	    opts, args = getopt.getopt(sys.argv[1:], "hvnsc", \
			    ["help","version","nosort","self","cname"])
	except getopt.error, msg:
	    print msg
	    print "for help use --help"
	    sys.exit(2)
	# process options
	for o, a in opts:
	    if o in ("-h", "--help"):
		print __doc__
		sys.exit(0)
	    elif o in ("-v", "--version"):
		print main.__doc__
		sys.exit(0)
	    elif o in ("-n", "--nosort"):
		nosort=1
	    elif o in ("-s", "--self"):
		self_profile=ref_profile
	    elif o in ("-c", "--cname"):
		cname=1
	# process arguments
    	#for arg in args:
	#    process(arg) # process() is defined elsewhere
	stockm=stockinfo(nosort=nosort,cname=cname,self_profile=self_profile)

	if (stockm.profile()):
		stockm.stock_monitor()


if __name__ == "__main__":
	main()

